package com.study.listener;

import java.io.UnsupportedEncodingException;
import java.util.Map;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.core.MessageProperties;

import com.study.common.OperateType;
import com.study.service.TestService;

public class TestListener implements MessageListener{
	
	private TestService service;

    public void start() {
        this.service = new TestService();
        this.service.init();
    }
    
//    public void listener(byte[] msg) {
//        System.out.println(msg);
//    }
//
//    public void listener(String msg) {
//    	System.out.println(msg);
//        String result = service.parse(msg);
//    }

	public void onMessage(Message message) {
		
		MessageProperties msgProp = message.getMessageProperties();
		Map<String,Object> heanderMap = msgProp.getHeaders();
//		for(Entry<String,Object> entry : heanderMap.entrySet()){
//			System.out.println(entry.getKey()+"="+entry.getValue());
//		}
		
		String optType = (String)heanderMap.get("opt_type");
		
		if(OperateType.ORDER_DOWN.equals(optType)){
			
		}else if(OperateType.ORDER_UPLOAD.equals(optType)){
			
		}else{
			
		}
		
		byte[] body = message.getBody();
		String s = "";
		try {
			s = new String(body, "utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		
		String result = service.parse(s);
		System.out.println("##########s="+s);
	}

}
